﻿@model IEnumerable<Eqwww.Domain.Models.SystemManage.ModuleModel>


@{
    ViewData["Title"] = "模块管理";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";


}

<div id="eq-operate">
    <div class="mdui-appbar mdui-color-white mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>

            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>

            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div id="xd-appbar" class="mdui-appbar mdui-color-white mdui-shadow-1">
    <div class="mdui-toolbar">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <div class="mdui-toolbar-spacer"></div>


        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>


    </div>
</div>
<div class="mdui-container-fluid mdui-m-t-1 mdui-m-b-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>

@section Scripts {
    <script>
            $(function () {
                //$('.eq-list-table').eqTable();

                gridTable();
                $('#refreshBtn').bind('click', function () {
                    //top.$.loadingLayer(true);
                    window.location.reload();
                });
            });

        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.dataGrid({
                treeGrid: true,
                treeGridModel: "adjacency",
                ExpandColumn: "Code",
                url: '/SystemManage/Module/IndexGridJson',
                mtype: "GET",
                styleUI: 'Bootstrap4',
                iconSet: 'fontAwesome',
                datatype: "json",
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden: true },
                    { label: '名称', name: 'Name', width: 150, sortable:false },
                    { label: '编码', name: 'Code', width: 100, sortable: false },
                    { label: '排序码', name: 'SortCode', width: 100, sortable: false},
                    {
                        label: '菜单', name: 'MenuMark', width: 100,  sortable:false,formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    {
                        label: '系统', name: 'IsSystem', width: 100, sortable: false, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    { label: '系统', name: 'IsSystem', hidden:true },
                    { label: 'Url', name: 'Url', width: 100, sortable: false },
                    {
                        label: '创建时间', name: 'CreateTime', width: 110, sortable: false, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    }

                ],
                height: getGridHeight(),
                shrinkToFit: true
            });

            $(window).resize(function () {
                $gridList.jqGrid('setGridHeight', getGridHeight()-20);
            });

        }

            function btn_create() {

                $.modalOpen({
                    id: 'form1255',
                    title: '新建模块',
                    url: '/SystemManage/Module/Create',
                    width: '100%',
                    height: '100%',
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
                return false;
            }

            function btn_edit() {
                var key = $('#gridTable').jqGridRowValue().Id;
                var isSystem = $('#gridTable').jqGridRowValue().IsSystem;
                //var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');
                if (!key) {
                    top.$.snackbar('未选中任何行！');
                    return false;
                }
                if (isSystem == 'True') {
                    top.$.snackbar('系统模块不允许修改！');
                    return false;
                }
                $.modalOpen({
                    id: 'form1255',
                    title: '修改模块',
                    url: '/SystemManage/Module/Edit?id=' + key,
                    width: '100%',
                    height: '100%',
                    callBack: function (iframeId) {
                        top.frames[iframeId].submitForm();
                    }
                });
            }

            function btn_details() {
                var key = $('#gridTable').jqGridRowValue().Id;
                if (!key) {
                    top.$.snackbar('未选中任何行！');
                    return false;
                }
                $.modalOpen({
                    id: 'Details',
                    title: '查看模块',
                    url: '/SystemManage/Module/Details?id=' + key,
                    width: '100%',
                    height: '100%',
                    isback: true,
                    hideConfirmBtn: true,
                    btn:null
                });
        }

        function btn_buttons() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'ModuleButton',
                title: '按钮管理',
                url: '/SystemManage/ModuleButton?moduleId=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn:true,
                btn: null
            });
        }

        function btn_claims() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'ModuleClaims',
                title: '声明管理',
                url: '/SystemManage/ModuleClaims?moduleId=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_autorenew() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }
            $.modalConfirm(
                '本操作将初始化新建、修改、删除、查看四个按钮，确定操作吗？',
                function (flag) {
                    if (flag) {
                        top.$.loadingBox(false);
                        window.setTimeout(function () {
                            $.ajax({
                                url: '/SystemManage/ModuleButton/InitialButtons',
                                data: { moduleId: key },
                                type: "post",
                                dataType: "json",
                                success: function (data) {
                                    top.$.loadingBox(true);
                                    if (data.state === "success") {
                                        top.$.snackbar('<i class="mdui-icon material-icons mdui-text-color-green">check</i> ' + data.message, data.state);
                                    } else {
                                        $.modalAlert(data.message, data.state);
                                    }
                                }

                            });
                        }, 500);
                    }
                }
            );

        }

            function btn_delete() {
                var key = $('#gridTable').jqGridRowValue().Id;
                if (!key) {
                    top.$.snackbar('未选中任何行！');
                    return false;
                }
                var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');

                if (isSystem == 'True') {
                    top.$.snackbar('系统模块不允许删除！');
                    return false;
                }
                $.deleteForm({
                    url: '/SystemManage/Module/Delete',
                    param: { id: key },
                    success: function () {
                        window.location.reload();

                    }
                })
        }

        function btn_updateissystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt:'确定将本模块提升为系统模块吗？',
                url: '/SystemManage/Module/UpdateIsSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateisnotsystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定将本模块降级为一般模块吗？',
                url: '/SystemManage/Module/UpdateIsNotSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }



    </script>
}

